home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / x2ftp / msdos / libs / knowhow4 / button.cpp < prev    next >
C/C++ Source or Header  |  1994-10-10  |  2KB  |  62 lines

  1. #include "button.h"
  2. #include "patterns.h"
  3. #include "khbgi.h"
  4.  
  5. Button::Button(rect r, char* txt, BORDERS b_type, int pat)
  6.      : Press(r, b_type)
  7.     {
  8.     if(txt)
  9.         text = strdup(txt);
  10.     else
  11.         text = NULL;
  12.     pattern = pat;
  13.     }
  14. /////////////////////////
  15. void Button::show()
  16.     {
  17.     settextstyle(DEFAULT_FONT, HORIZ_DIR, 1);
  18.     settextjustify(CENTER_TEXT, CENTER_TEXT);
  19.     setcolor((int)pColorSet->colors.ATTR_COLOR);
  20.  
  21.     rect r = screenRect(rectangle);
  22.     bar(r, (int)pColorSet->colors.BAK_COLOR,
  23.         (int)pColorSet->colors.FILL_COLOR, (uchar*)::pattern[pattern]);
  24.     int i;
  25.     char* txt = text;
  26.     for(i = 0; txt = strchr(txt, '\n'); i++) // counts '\n' in string
  27.     txt++;
  28.     int start = i * textheight("L") * 5 / 8;  // start for few lines
  29.                               // output
  30.     txt = text;
  31.     char t[80];                               // maximum length
  32.     while(i > 0)
  33.     {
  34.     memset(t, '\0', 79);
  35.     int n = strchr(txt, '\n') - txt;
  36.     strncpy(t, txt, n);
  37.     ::outtextxy(r.origin.X + r.width() / 2,
  38.         r.origin.Y + r.height() / 2 - start, t);
  39.     txt += n + 1; i--;
  40.     start -= textheight("L") * 5 / 4;
  41.     }
  42.     ::outtextxy(r.origin.X + r.width() / 2,
  43.         r.origin.Y + r.height() / 2 - start, txt);
  44.     Frame::show();
  45.     }
  46. /////////////////////
  47. /*
  48. void main()
  49.     {
  50.     if(!init_KNOW_HOW())
  51.         return;
  52.     setfillstyle(SOLID_FILL, pColorSet->colors.BAK_COLOR);
  53.     bar(0, 0, getmaxx(), getmaxy());
  54.  
  55.     Button b(rect(1, 1, 15, 6), "HELLO,\nWORLD\n!!!", SHOW_BORDER, 16);
  56.     b.show();
  57.     b.exe();
  58.  
  59.     close_KNOW_HOW();
  60.     closegraph();
  61.     }
  62. */